package sixteenthDay;

public class SumNumbers {

    public int sumNumbers(TreeNode root) {
        return dfs(root,0);
    }
    public int dfs(TreeNode node, int sum) {
        if (node == null) {
            return 0;
        }
        int curSum = sum * 10 + node.val;
        if (node.left == null && node.right == null) {
            return curSum;
        }
        return dfs(node.left, curSum) + dfs(node.right, curSum);
    }
}
